(function() {
	/******弹窗的出现与关闭*****/
	var img = document.getElementsByClassName('img')[0];
	var bei = document.getElementsByClassName('bei')[0];
	var btn = bei.getElementsByClassName('iconfont')[0];
	img.addEventListener('click', function() {
		bei.style.display = 'block';
	});
	btn.addEventListener('click', function() {
		this.parentNode.parentNode.style.display = 'none';
	});

	/*****添加桌子的数量******/
	var arr = ['', '一', '二', '三', '四', '五', '六', '七', '八', '九'];
	var seat = document.getElementsByClassName('seat')[0];
	var section = document.getElementsByClassName('section');
	var add = document.getElementsByClassName('add')[0];
	add.addEventListener('click', function() {
		var tem = section[0].cloneNode(true);
		if(section.length < 10) {
			tem.querySelector('p').innerHTML = '第' + (arr[section.length]) + '席';
		} else if(section.length < 20) {
			tem.querySelector('p').innerHTML = '第' + '十' + arr[section.length % 10] + '席';
		} else {
			tem.querySelector('p').innerHTML = '第' + arr[parseInt(section.length / 10)] + '十' + arr[section.length % 10] + '席';
		}
		seat.insertBefore(tem, section[section.length - 1]);
		big();
	});

	/**********桌子的放大与缩小*************/

	var content = document.getElementsByClassName('content');

	function big() {
		for(var i = 0; i < content.length - 1; i++) {
			content[i].index = i;
			content[i].addEventListener('click', function() {
				for(var j = 0; j < content.length; j++) {
					content[j].parentNode.style.display = 'none';
				};
				this.parentNode.style.width = '100%';
				this.parentNode.style.height = '100%';
				this.parentNode.style.display = 'block';
				this.style.zIndex = '4';
				$('.home').css('display', 'none');
				$('.nv').css('display', 'none');
				$('.img').css('display', 'none');
				$('.bg').css('z-index', '3')
				if(this.index == 0) {
					this.style.transform = 'scale(2) translateY(135px)';
				} else {
					this.style.transform = 'scale(2.7) translateY(100px)';
				}

			})
		}
	}
	big();

	/******恢复原来的样式***********/

	var bg = document.getElementsByClassName('bg')[0];
	bg.addEventListener('click', function() {
		for(var i = 0; i < content.length - 1; i++) {
			content[i].index = i;
			for(var j = 0; j < content.length; j++) {
				content[j].parentNode.style.display = 'block';
			}
			if(i == 0) {
				content[i].parentNode.style.width = '50%';
				content[i].parentNode.style.height = 'auto';
				content[i].parentNode.style.margin = '0 auto';
			} else {
				content[i].parentNode.style.width = '50%';
				content[i].parentNode.style.height = 'auto';
			}

			content[i].parentNode.style.display = 'block';
			content[i].style.zIndex = 'none';
			$('.nv').css('display', 'block');
			$('.img').css('display', 'block');
			$('.bg').css('z-index', '-9999');
			$('.home').css('display', 'block');
			if(this.index == 0) {
				content[i].style.transform = 'scale(1) translateY(0)';
			} else {
				content[i].style.transform = 'scale(1) translateY(0)';
			}

		}
	});

	/***********座位做人***************/

	function seat_people() {
		var append = document.getElementsByClassName('append');
		for(var h = 0; h < append.length - 6; h++) {
			append[h].addEventListener('click', function(e) {
				e.stopPropagation();
				if(h <= stores.length) {
					this.children[0].innerHTML = '<img src=' + stores[0].src + '/>';
				} else {
					this.children[0].innerHTML = '<img src=' + stores[1].src + '/>'
				}
			});
		};
	};
	one();

	/*********获取json文件******/

	var xmlhttp;
	if(window.XMLHttpRequest) {
		//				IE7 + , Firefox, Chrome, Opera, Safari 浏览器执行代码
		xmlhttp = new XMLHttpRequest();
	} else {
		// IE6, IE5 浏览器执行代码
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.open('GET', '../js/img.json');
	xmlhttp.send();
	xmlhttp.addEventListener('readystatechange', function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			stores = JSON.parse(xmlhttp.responseText);
			return stores;
		};
	});

	/********婚宴人*****/
	var name = document.getElementsByClassName('name')[0];
	name.innerText = '伟健';

	/*******音乐动画效果********/

	$(function() {
		var music = document.getElementById('music');
		$('#musicbutton').click(function() {
			if(music.paused) {
				music.play();
				$("#musicbutton").removeClass("pause").addClass("music");
				$('.musicbutton .iconfont').css({
					'animation': 'music 4s infinite '
				});
				$('.musicbutton').css({
					'animation': 'mu 4s infinite '
				});
				$('i').removeClass('icon-yinle').addClass('icon-guanbiyinle')
			} else {
				music.pause();
				$('#musicbutton').removeClass('play').addClass('music');
				$('.musicbutton .iconfont').css({
					'animation': 'none'
				});
				$('.musicbutton').css({
					'animation': 'none '
				});
				$('i').removeClass('icon-guanbiyinle').addClass('icon-yinle');
			}
		})
	});

	/***********糖果动画效果*********/

	function sugar() {
		var sugar = document.getElementsByClassName('sugar')[0];

		/******添加糖果***/
		for(var p = 0; p < 30; p++) {
			sugar.innerHTML += '<img src="../images/sugar.png" style="width:50px;z-index:9999;position: absolute;left:' + Math.random() * 550 + 'px ;top:' + Math.random() * (-1000) + 'px;  " > '
		};
		/******糖果掉落效果***/
		for(var t = 0; t < 30; t++) {
			$("img").eq(t).transition({
				top: Math.random() * 1000 + 260,
				rotate: Math.random() * 100 + 300 + 'deg',
				opacity: 0
			}, Math.random() * 2000 + 2000)
		}
	};

})();